package com.example.shop.flush;

import android.os.Bundle;
import android.os.Handler;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AppCompatActivity;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    private SwipeRefreshLayout mRefreshLayout;
    private ListView mLv;

    private ArrayAdapter<String> mStringArrayAdapter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.refresh_layout);
        mLv = (ListView) findViewById(R.id.lv);

        List<String> mStrings=new ArrayList<>();
        for (int i='A';i<='Z';i++){
            mStrings.add("当前是数据----->"+(char)i);
        }
        mStringArrayAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, mStrings);
        mLv.setAdapter(mStringArrayAdapter);
        //设置刷新时动画的颜色，可以设置4个
        mRefreshLayout.setColorSchemeResources(android.R.color.holo_blue_light, android.R.color.holo_red_light, android.R.color.holo_orange_light, android.R.color.holo_green_light);
        mRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

            @Override
            public void onRefresh() {
                // TODO Auto-generated method stub
                new Handler().postDelayed(new Runnable() {

                    @Override
                    public void run() {

                        mStringArrayAdapter.insert("xxxNew",0);
                        //结束刷新
                        mRefreshLayout.setRefreshing(false);
                    }
                }, 6000);
            }
        });
    }
}
